home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2006 May / PCWMAY06.iso / Software / Freeware / First Page 2006 3.00 / fp2006-final-3.00-setup.exe / {app} / Iscripts / Cookie / display-amount-of-times-user-has-visted-2.izs < prev    next >
Text File  |  2005-09-28  |  6KB  |  203 lines

  1. <!NOWIZARD>
  2.  
  3. <!TITLE>Using cookies to display number of times
  4. a user has visited your page II
  5. <!/TITLE>
  6.  
  7. <!DESCRIPTION>This script keeps track of the number of times a surfer has visited your page, and alerts the surfer of this info. Also comes with buttons to allow him/her to reset this info. Quite neat.
  8. <!/DESCRIPTION> 
  9.  
  10. <!CATEGORY>cookies<!/CATEGORY>
  11.  
  12. <!SCRIPT>
  13. <!-- START OF SCRIPT -->
  14. <SCRIPT LANGUAGE="JavaScript">
  15.  
  16. function getCookieVal (offset) {
  17. var endstr = document.cookie.indexOf (";", offset);
  18. if (endstr == -1)
  19. endstr = document.cookie.length;
  20. return unescape(document.cookie.substring(offset, endstr));
  21. }
  22. function GetCookie (name) {
  23. var arg = name + "=";
  24. var alen = arg.length;
  25. var clen = document.cookie.length;
  26. var i = 0;
  27. while (i < clen) {
  28. var j = i + alen;
  29. if (document.cookie.substring(i, j) == arg)
  30. return getCookieVal (j);
  31. i = document.cookie.indexOf(" ", i) + 1;
  32. if (i == 0) 
  33. break; 
  34. }
  35. return null;
  36. }
  37. function SetCookie (name, value) {
  38. var argv = SetCookie.arguments;
  39. var argc = SetCookie.arguments.length;
  40. var expires = (2 < argc) ? argv[2] : null;
  41. var path = (3 < argc) ? argv[3] : null;
  42. var domain = (4 < argc) ? argv[4] : null;
  43. var secure = (5 < argc) ? argv[5] : false;
  44. document.cookie = name + "=" + escape (value) +
  45. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  46. ((path == null) ? "" : ("; path=" + path)) +
  47. ((domain == null) ? "" : ("; domain=" + domain)) +
  48. ((secure == true) ? "; secure" : "");
  49. }
  50. function DisplayInfo() {
  51. var expdate = new Date();
  52. var visit;
  53. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  54. if(!(visit = GetCookie("visit"))) 
  55. visit = 0;
  56. visit++;
  57. SetCookie("visit", visit, expdate, "/", null, false);
  58. var message;
  59. if(visit == 1) 
  60. message="         Welcome to my page!";
  61. if(visit== 2) 
  62. message="           I see you came back !";
  63. if(visit == 3) 
  64. message="               Oh, it's you again!";
  65. if(visit == 4)
  66. message="            You must be curious!"; 
  67. if(visit == 5) 
  68. message="      You're practically a regular!";
  69. if(visit == 6) 
  70. message="              You need a hobby!";
  71. if(visit == 7)
  72. message="             Nothing better to do?"; 
  73. if(visit == 8) 
  74. message="            Don't you ever sleep?";
  75. if(visit == 9)
  76. message="                      Get a life!!!"; 
  77. if(visit >= 10) 
  78. message="  Rent is due on the 1st of the month!";
  79.   alert("\n"+"Your browser has visited this page               \n"
  80.             +"                              "+visit+"\n"
  81.             +"                          time(s)."+"\n"+"\n"
  82.             +message);
  83. }
  84. function ResetCounts() {
  85. var expdate = new Date();
  86. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  87. visit = 0;
  88. SetCookie("visit", visit, expdate , "/", null, false);
  89. history.go(0);
  90. }
  91.  
  92. window.onload=DisplayInfo
  93. </Script>
  94.  
  95.  
  96. <FORM>
  97. <CENTER>
  98. <INPUT NAME="update" TYPE="BUTTON" VALUE="Revisit  Page" OnClick="history.go(0)">
  99. <INPUT NAME="reset" TYPE="BUTTON" VALUE="Reset Counter" OnClick="ResetCounts()">
  100. </CENTER>
  101. </FORM>
  102.  
  103. <!-- END OF SCRIPT -->
  104. <!/SCRIPT>
  105.  
  106. <!PREVIEW>
  107. <!-- START OF SCRIPT -->
  108. <SCRIPT LANGUAGE="JavaScript">
  109.  
  110. function getCookieVal (offset) {
  111. var endstr = document.cookie.indexOf (";", offset);
  112. if (endstr == -1)
  113. endstr = document.cookie.length;
  114. return unescape(document.cookie.substring(offset, endstr));
  115. }
  116. function GetCookie (name) {
  117. var arg = name + "=";
  118. var alen = arg.length;
  119. var clen = document.cookie.length;
  120. var i = 0;
  121. while (i < clen) {
  122. var j = i + alen;
  123. if (document.cookie.substring(i, j) == arg)
  124. return getCookieVal (j);
  125. i = document.cookie.indexOf(" ", i) + 1;
  126. if (i == 0) 
  127. break; 
  128. }
  129. return null;
  130. }
  131. function SetCookie (name, value) {
  132. var argv = SetCookie.arguments;
  133. var argc = SetCookie.arguments.length;
  134. var expires = (2 < argc) ? argv[2] : null;
  135. var path = (3 < argc) ? argv[3] : null;
  136. var domain = (4 < argc) ? argv[4] : null;
  137. var secure = (5 < argc) ? argv[5] : false;
  138. document.cookie = name + "=" + escape (value) +
  139. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  140. ((path == null) ? "" : ("; path=" + path)) +
  141. ((domain == null) ? "" : ("; domain=" + domain)) +
  142. ((secure == true) ? "; secure" : "");
  143. }
  144. function DisplayInfo() {
  145. var expdate = new Date();
  146. var visit;
  147. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  148. if(!(visit = GetCookie("visit"))) 
  149. visit = 0;
  150. visit++;
  151. SetCookie("visit", visit, expdate, "/", null, false);
  152. var message;
  153. if(visit == 1) 
  154. message="         Welcome to my page!";
  155. if(visit== 2) 
  156. message="           I see you came back !";
  157. if(visit == 3) 
  158. message="               Oh, it's you again!";
  159. if(visit == 4)
  160. message="            You must be curious!"; 
  161. if(visit == 5) 
  162. message="      You're practically a regular!";
  163. if(visit == 6) 
  164. message="              You need a hobby!";
  165. if(visit == 7)
  166. message="             Nothing better to do?"; 
  167. if(visit == 8) 
  168. message="            Don't you ever sleep?";
  169. if(visit == 9)
  170. message="                      Get a life!!!"; 
  171. if(visit >= 10) 
  172. message="  Rent is due on the 1st of the month!";
  173.   alert("\n"+"Your browser has visited this page               \n"
  174.             +"                              "+visit+"\n"
  175.             +"                          time(s)."+"\n"+"\n"
  176.             +message);
  177. }
  178. function ResetCounts() {
  179. var expdate = new Date();
  180. expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
  181. visit = 0;
  182. SetCookie("visit", visit, expdate , "/", null, false);
  183. history.go(0);
  184. }
  185.  
  186. window.onload=DisplayInfo
  187. </Script>
  188.  
  189.  
  190. <FORM>
  191. <CENTER>
  192. <INPUT NAME="update" TYPE="BUTTON" VALUE="Revisit  Page" OnClick="history.go(0)">
  193. <INPUT NAME="reset" TYPE="BUTTON" VALUE="Reset Counter" OnClick="ResetCounts()">
  194. </CENTER>
  195. </FORM>
  196.  
  197.  
  198.  
  199. <!-- END OF SCRIPT -->
  200. <!/PREVIEW>
  201.  
  202. <!RELATED>NONE<!/RELATED>
  203.